/**
 * 
 */
let searchV = new Vue({
	el: '#searchDiv',
	data: {
		count: 0,
		countTotal:0,
        loading: false,
		userisLogin: false,
		hrisLogin: false,
		id: '',
		username: '',
		password: '',
		dialogForm2Visible: false,
		dialogForm1Visible: false,
		option:
		{
			area: '不限',
			education: '不限',
			salary: '不限',
			jobtime: '不限'
		},
		areaList: [],
		educationList: [],
		salaryList: [],
		jobtimeList: [],
		searchResult: JSON.parse(sessionStorage.getItem("jobList")),
		input1: "",//搜索框的绑定
		select: "职位",
		items2: [
			{
				title: "首页",
				index: "/index",
				class: "index1"
			},
			{
				title: "秋招日历",
				index: "/ftime",
				class: "index2"
			},
			{
				title: "大厂信息",
				index: "/factory",
				class: "index3"
			},
			{
				title: "校招",
				index: "/school",
				class: "index4"
			},
			{
				title: "offer直通车",
				index: "/offer",
				class: "index5"
			}
		]
	},
	computed: {
      noMore () {
        return this.count >= this.countTotal;
      },
      disabled () {
        return this.noMore;
      }
    },
	methods: {
		resetSelect(){
			this.option.area = '不限';
			this.option.education = '不限';
			this.option.salary = '不限';
			this.option.jobtime = '不限';
		},
		load () {
        this.loading = true;
        setTimeout(() => {
		
		  this.count+=1;
		 
          this.loading = false;
        }, 1400)
      },
	getBussiness(bname){
					sessionStorage.setItem("bname",bname);
					window.location.href="http://localhost:8082/usert/b";
				},
		getJobDetails(jid){
					sessionStorage.setItem("jid",jid);
					console.log(jid)
					window.location.href="http://localhost:8082/usert/j";
				},
		search(select, input) {
			if (select === '职位') {
				this.selectJobp(input);
			}
			if (this.select === '公司') {
				this.findByBuss(input);
			}
		},
		findByBuss(bname) {
			let data = new FormData();
			data.append("bname", bname);

			axios.post('/usert/findJob', data).then(resp => {
				sessionStorage.setItem("jobList", JSON.stringify(resp.data));
				sessionStorage.setItem("jobname", bname);
				window.location = "http://localhost:8082/usert/search?jobname=" + bname;
				console.log(JSON.parse(sessionStorage.getItem("jobList")));
			}).catch();
		},
		selectJobp(jobpart) {
			//console.log(jobpart);

			let data = new FormData();
			data.append("jobname", jobpart);

			axios.post('/usert/findJob', data).then(resp => {
				sessionStorage.setItem("jobList", JSON.stringify(resp.data));
				sessionStorage.setItem("jobname", jobpart);
				window.location = "http://localhost:8082/usert/search";
				console.log(JSON.parse(sessionStorage.getItem("jobList")));
			}).catch();
		},

		searchByselect() {
			let bpro = this.option.area;
			let jeducation = this.option.education;
			let jsalary = this.option.salary;
			let jtime = this.option.jobtime;
			this.count = 0;
			axios.get('/usert/getbykeys', {
				params: {
					bpro: bpro === '不限' ? '' : bpro,
					jeducation: jeducation === '不限' ? '' : jeducation,
					jsalary: jsalary === '不限' ? '' : jsalary,
					jtime: jtime === '不限' ? '' : jtime
				}
			}).then(resp => {
				console.log("selectresult" + resp.data);
				this.searchResult = resp.data;
				
				this.countTotal = this.searchResult.length;
				console.log("筛选total："+this.countTotal);
				
			}).catch();
		},
		getid() {
			axios.post('/usert/getid').then(resp => {
				this.id = "您好";
			}).catch();
		},
		isLogin() {
			axios.post('/usert/islogin').then(resp => {
				this.userisLogin = resp.data;
				this.hrisLogin = resp.data;
				console.log(this.userisLogin + '--' + this.hrisLogin);

			}).catch();
		},
		searchInput() {
			if (sessionStorage.getItem("jobname") !== null)
				this.input1 = sessionStorage.getItem("jobname");
		},
		getSelectList() {
			axios.post('/manager/getSelection')
				.then(resp => {
					if (resp) {
						let list = resp.data;
						//this.searchResult = list;
						let areaSet = new Set();
						let educationSet = new Set();
						let salarySet = new Set();
						let jobtimeSet = new Set();
						for (let i = 0; i < list.length; i++) {
							areaSet.add(list[i].bpro);
							educationSet.add(list[i].jeducation);
							salarySet.add(list[i].jsalary);
							jobtimeSet.add(list[i].jtime);
						}
						this.areaList = Array.from(areaSet);
						this.educationList = Array.from(educationSet);
						this.salaryList = Array.from(salarySet);
						this.jobtimeList = Array.from(jobtimeSet);
						this.countTotal = this.searchResult.length;
						console.log("zongchangdu:"+this.countTotal);
					}
				}).catch(error=>{
					console.log("错误信息"+error);
				});
		},

	},
	created() {
		this.getSelectList();
		this.searchInput();
		this.isLogin();
		this.getid();
	}
});